<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Single-level search</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ldap-get-values.html">« ldap_get_values</a></li>
      <li style="float: right;"><a href="function.ldap-mod_add-ext.html">ldap_mod_add_ext »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ldap.html">LDAP 函数</a></li>
    <li>Single-level search</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ldap-list" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_list</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ldap_list</span> &mdash; <span class="dc-title">Single-level search</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ldap-list-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_list</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.ldap-connection.html" class="type LDAP\Connection">LDAP\Connection</a></span>|<span class="type">array</span></span> <code class="parameter">$ldap</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$base</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">string</span></span> <code class="parameter">$filter</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$attributes</code><span class="initializer"> = []</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$attributes_only</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$sizelimit</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$timelimit</code><span class="initializer"> = -1</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$deref</code><span class="initializer"> = <strong><code>LDAP_DEREF_NEVER</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">array</span><span class="type"></span></span> <code class="parameter">$controls</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type"><a href="class.ldap-result.html" class="type LDAP\Result">LDAP\Result</a></span>|<span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Performs the search for a specified <code class="parameter">filter</code> on the
   directory with the scope <strong><code>LDAP_SCOPE_ONELEVEL</code></strong>.
  </p>
  <p class="para">
   <strong><code>LDAP_SCOPE_ONELEVEL</code></strong> means that the search should only
   return information that is at the level immediately below the
   <code class="parameter">base</code> given in the call.
   (Equivalent to typing &quot;<strong class="command">ls</strong>&quot; and getting a list of files and folders in the
   current working directory.)
  </p>
   <p class="para">It is also possible to perform parallel searches. In this case, the first argument should be an array of
<span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span> instances, rather than a single one.
If the searches should not all use the same base DN and filter, an array of base DNs and/or an array of filters can be passed as arguments instead.
These arrays must be of the same size as the <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span> instances array,
since the first entries of the arrays are used for one search, the second entries are used for another, and so on.
When doing parallel searches an array of <span class="classname"><a href="class.ldap-result.html" class="classname">LDAP\Result</a></span> instances is returned, except in case of error, when the return value will be <strong><code>false</code></strong>.</p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-list-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">ldap</code></dt>

     <dd>

      <p class="para">
       通过 <span class="function"><a href="function.ldap-connect.html" class="function">ldap_connect()</a></span> 返回的 <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span> 实例。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">base</code></dt>

     <dd>

      <p class="para">
       The base DN for the directory.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">filter</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">attributes</code></dt>

     <dd>

      <p class="para">
       An array of the required attributes, e.g. array(&quot;mail&quot;, &quot;sn&quot;, &quot;cn&quot;).
       Note that the &quot;dn&quot; is always returned irrespective of which attributes
       types are requested.
      </p>
      <p class="para">
       Using this parameter is much more efficient than the default action
       (which is to return all attributes and their associated values).
       The use of this parameter should therefore be considered good
       practice.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">attributes_only</code></dt>

     <dd>

      <p class="para">
       Should be set to 1 if only attribute types are wanted. If set to 0
       both attributes types and attribute values are fetched which is the
       default behaviour.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">sizelimit</code></dt>

     <dd>

      <p class="para">
       Enables you to limit the count of entries fetched. Setting this to 0
       means no limit.
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        This parameter can NOT override server-side preset sizelimit. You can
        set it lower though.
       </p>
       <p class="para">
        Some directory server hosts will be configured to return no more than
        a preset number of entries. If this occurs, the server will indicate
        that it has only returned a partial results set. This also occurs if
        you use this parameter to limit the count of fetched entries.
       </p>
      </p></blockquote>
     </dd>

    
    
     <dt>
<code class="parameter">timelimit</code></dt>

     <dd>

      <p class="para">
       Sets the number of seconds how long is spend on the search. Setting
       this to 0 means no limit.
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        This parameter can NOT override server-side preset timelimit. You can
        set it lower though.
       </p>
      </p></blockquote>
     </dd>

    
    
     <dt>
<code class="parameter">deref</code></dt>

     <dd>

      <p class="para">
       Specifies how aliases should be handled during the search. It can be
       one of the following:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_NEVER</code></strong> - (default) aliases are never
          dereferenced.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_SEARCHING</code></strong> - aliases should be
          dereferenced during the search but not when locating the base object
          of the search.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_FINDING</code></strong> - aliases should be
          dereferenced when locating the base object but not during the search.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>LDAP_DEREF_ALWAYS</code></strong> - aliases should be dereferenced
          always.
         </span>
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">controls</code></dt>

     <dd>

      <p class="para">
       Array of <a href="ldap.controls.html" class="link">LDAP Controls</a> to send with the request.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-list-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回 <span class="classname"><a href="class.ldap-result.html" class="classname">LDAP\Result</a></span> 实例、 <span class="classname"><a href="class.ldap-result.html" class="classname">LDAP\Result</a></span> 实例数组 或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-list-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">ldap</code> 参数接受 <span class="classname"><a href="class.ldap-connection.html" class="classname">LDAP\Connection</a></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

      <tr>
 <td>8.1.0</td>
 <td>
  Returns an <span class="classname"><a href="class.ldap-result.html" class="classname">LDAP\Result</a></span> instance now;
  previously, a <a href="language.types.resource.html" class="link">资源(resource)</a> was returned.
 </td>
</tr>

      <tr>
<td>8.0.0</td>
<td>
  <code class="parameter">controls</code> is nullable now; previously, it defaulted to <code class="literal">[]</code>.
</td>
</tr>

      <tr>
       <td>7.3.0</td>
       <td>
        Support for <code class="parameter">controls</code> added
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-list-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4347">
    <p><strong>示例 #1 Produce a list of all organizational units of an organization</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$ds&nbsp;is&nbsp;a&nbsp;valid&nbsp;LDAP\Connection&nbsp;instance&nbsp;for&nbsp;a&nbsp;directory&nbsp;server<br /><br /></span><span style="color: #0000BB">$basedn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$justthese&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"ou"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_list</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$basedn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ou=*"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$justthese</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_get_entries</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sr</span><span style="color: #007700">);<br /><br />for&nbsp;(</span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">"count"</span><span style="color: #007700">];&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">][</span><span style="color: #DD0000">"ou"</span><span style="color: #007700">][</span><span style="color: #0000BB">0</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ldap-list-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ldap-search.html" class="function" rel="rdfs-seeAlso">ldap_search()</a> - Search LDAP tree</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>